package sg.techstudio.suntec.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;

//@Component("customAccessDeniedHandler")
public class CustomAccessDeniedHandler implements AccessDeniedHandler{
	private static final Log log = LogFactory.getLog(CustomAccessDeniedHandler.class);
	
	@Override
	public void handle(HttpServletRequest request, HttpServletResponse response,
			AccessDeniedException accessDeniedException) throws IOException, ServletException {
		log.debug("20130503: requested url: "+request.getRequestURL().toString());
		if(StringUtils.contains(request.getRequestURL().toString(), "addmodify.sw")) {
			response.sendError(HttpServletResponse.SC_FORBIDDEN);
			return;
		}
		response.sendRedirect("/cms/dashboard/login.sw");
	}

}
